package com.ctgu.牛客网.简单排序;
import java.io.*;

/**
 * @author: Backdiy
 * @data: 2021/3/30 20:01
 * @desc 求和
 */
public class 求和 {
    static int mod = 10007;
    static int[] numbs;
    static int[][] cnt;
    static int[][][] numSum;
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    public static void main(String[] args) throws IOException {
        int n, m;
        n = Input.nextInt();
        m = Input.nextInt();
        numbs = new int[n + 10];
        cnt = new int[m + 10][2];
        numSum = new int[m + 10][3][2];
        for (int i = 1; i <= n; i++) {
            numbs[i] = Input.nextInt()%mod;
        }
        int sum = 0;
        for (int i = 1; i <= n; i++) {
            int color = Input.nextInt();
            numSum[color][0][i % 2] = (numSum[color][0][i % 2] + numbs[i] * i) % mod;
            numSum[color][1][i % 2] = (numSum[color][1][i % 2] + numbs[i]) % mod;
            numSum[color][2][i % 2] = (numSum[color][2][i % 2] + i) % mod;
            cnt[color][i % 2]++;
        }
        for (int i = 1; i <= m; i++) {
            for (int j = 0; j < 2; j++) {
                sum = (sum + (numSum[i][0][j] * (cnt[i][j]-2))%mod + (numSum[i][1][j]*numSum[i][2][j])%mod) % mod;
            }
        }
        out.println(sum);
        out.flush();
    }
}

class Input {
    static StreamTokenizer streamTokenizer = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    static String readLine() throws IOException {
        return bufferedReader.readLine();
    }

    static double nextDouble() throws IOException {
        streamTokenizer.nextToken();
        return (double) streamTokenizer.nval;
    }

    static int nextInt() throws IOException {
        streamTokenizer.nextToken();
        return (int) streamTokenizer.nval;
    }
}